package com;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.Part;

import web.annotation.Method;
import web.annotation.Param;
import web.annotation.Type;
import web.util.FileOperator;

@Type("fileReciever")
public class FileReciever {
	
	@Method("fileRec")
	public static void fileRec(@Param("file")Part part){
		String filePath ="E:"+File.separator+ new SimpleDateFormat("yyyy-MM-dd").format(new Date())+File.separator;
		String fileName = part.getHeader("content-disposition");
		fileName = fileName.substring(fileName.lastIndexOf("=")+2, fileName.length()-1);
		
		InputStream is = null;
		try {
			is = part.getInputStream();
			FileOperator.create(fileName, filePath,is);
			//FileOperator.delete(filePath+fileName);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		
	}
}
